home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1049 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.9 KB

  1. Path: newsfeed.internetmci.com!xmission!news
  2. From: tknarr@xmission.com  ( Todd Knarr )
  3. Newsgroups: comp.lang.eiffel,comp.lang.ada,comp.edu,comp.lang.c,comp.lang.c++,comp.lang.modula2,comp.lang.modula3
  4. Subject: Re: Hungarian notation
  5. Date: 9 Jan 1996 02:17:54 GMT
  6. Organization: Chaos Central
  7. Message-ID: <4csj8i$gsa@news.xmission.com>
  8. References: <30C40F77.53B5@swsbbs.com> <30EF0415.6FE1@tus.ssi1.com> <1996Jan7.045815.8676@ohstpy> <4cpb00$nqk@news.xmission.com> <hawkfish-0801960904580001@blv-pm3-ip24.halcyon.com>
  9. Reply-To: tknarr@xmission.com ( Todd Knarr )
  10. NNTP-Posting-Host: slc31.xmission.com
  11. X-Newsreader: IBM NewsReader/2 v1.2
  12.  
  13. In <hawkfish-0801960904580001@blv-pm3-ip24.halcyon.com>, hawkfish@punchdeck.com (Richard Wesley) writes:
  14.  
  15. >I've found it useful to use typedefs for all sorts of things like this. 
  16. >Looping through a FooArray with a FooIndex is much more robust than using
  17. >a long or something.
  18.  
  19. I try to avoid syntactic-saccharine typedefs when possible. There's no
  20. language-level gain from typedef'ing an int or long to something else
  21. just for that, and it virtually requires an explosion of variables to
  22. deal with multiple arrays of different types. The result of using several
  23. different variables to step through several different arrays at different
  24. times, just because those arrays have elements of different types, tends
  25. to be confusion. When the index is really significant then it makes sense
  26. to use seperate variables ( eg. when nCurrentMerchItem holds the index of
  27. the current item as other processing is done ), but as was pointed out
  28. there are a lot of constructions where the index is only significant for
  29. a line or two of code ( where your code is saying, basically, "Do >this<
  30. to every item in the array." ).
  31.  
  32. One of my rules is that, when I do something like that, I use integer
  33. variables like i and j. That maps nicely to the uses of such letters in
  34. math classes and the like. I can then tell instantly whether the indexes
  35. are significant or just grind work.
  36.  
  37. >This is reasonable for C, but these days I find myself using auto_ptr and
  38. >my own auto_array templates to deal with this problem.  On the other hand,
  39. >it could still be useful inside a class that used an array to represent
  40. >something (e.g. a string).
  41.  
  42. Even in a lot of higher-level things like your auto_array it makes sense
  43. to index things by an integral value. There's a significant gain in safety
  44. at times, but at others you simply introduce redundant checks. If, for
  45. instance, an index is validated once and never altered after that, there
  46. is no need to revalidate it on every access. ( NB: being certain the index
  47. will never become invalid is, of course, the trick. )
  48.  
  49. --
  50. Todd Knarr : tknarr@xmission.com      |  finger for PGP public key
  51.                                       |  Member, USENET Cabal
  52.  
  53. Seriously, I don't want to die just yet.  I don't care how
  54. good-looking they are, I! don't! want! to! die!"
  55.                                         -- Megazone ( UF1 )
  56.  
  57.